package com.letou.ls.uitl;

import android.content.Context;

import org.apache.table.*;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.regex.Pattern;

/**
 * Created by tengxp on 16/3/20.
 */
public class Util {
    public static final Pattern CHINESE = Pattern.compile("([\u4e00-\u9fa5]+)");

    public static String getDataLine(Context context) {

        String dateline = "";
        if (Constant.getCurrentLottery() != null) {
            dateline = " 截止日期:" + Constant.getExpirationTime();
            dateline = dateline + "  版本号:" + Constant.getCurrentVersion(context);
            dateline = dateline
                    + "  站号:"
                    + org.apache.table.PreferencesUtils.getString(context,
                    Constant.PRE_TAG_USERNAME);
        }
        return dateline;
    }

    public static List<String> split(String text) {
        String[] array = CHINESE.split(text);
        System.out.println(Arrays.toString(array));

        ArrayList<String> list = new ArrayList<String>();
        // head
        int index;
        for (String s : array) {
            index = text.indexOf(s);
            if (index > 0) {
                list.add(text.substring(0, index));
            }

            for (int i = 0; i < s.length(); i++) {
                list.add(s.substring(i, i + 1));
            }

            text = text.substring(index + s.length());
        }

        if (text != null && text.length() > 0) list.add(text);

        array = new String[list.size()];
        System.out.println(Arrays.toString(list.toArray(array)));
        return list;

    }
}
